import unittest
from common.functions import browser_operation
from page.backstage.backstage_login_page import Backstage

# 准备管理员账号密码
userinfo = {
    'username': 'admin',
    'password': 'admin123'
}


class BackstageTestCase(unittest.TestCase):
    # 大夹子
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = browser_operation()
        # 创建Backstage对象
        cls.backstage = Backstage(driver)

    def test_01_login(self):
        # 请求目标网址
        self.backstage.get_website(self.backstage.backstage_url)
        # 隐式等待
        self.backstage.implicitly_wait()
        # 点击xx
        self.backstage.click_X()
        # 点击ECshop账号登录方式logo
        self.backstage.backstage_login()
        # 账号密码输入
        self.backstage.input_username(userinfo['username'])
        # 密码输入
        self.backstage.input_password(userinfo['password'])
        # 点击登录按钮
        self.backstage.btn_login()
        # 切换到菜单栏框架frame
        self.backstage.frame()

        # 获取登陆后的用户名文本
        username = self.backstage.next_login()
        # 断言
        self.assertEqual('admin', username)

    @classmethod
    def tearDownClass(cls) -> None:
        # 退出
        cls.backstage.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
